/**
 * Copyright (c) 2002 qc&Bull Co.,LTD
 * All right reserved.
 */
package cn.zxd.pub;


import cn.zxd.util.*;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

//import com.bull.dp.subservice.ShService.ParamUtil;

/**
 * <p>Title: Web业务系统</p>
 * <p>Description:业务系统的公共业务处理函数
 * 该类包含所有业务处理中的公共函数，和以前系统中的funpub.4gl
 * 文件相对应。在这个类中，所有的函数都采用Static的类型，所有需要的数据都是
 * 通过参数传入的，在本类中不采用通过属性传递数据的方法。 </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: qc&Bull</p>
 * @author YT
 * @version 1.0
 */
public class PubFun {

    public PubFun() {
    }

    /**
     * 日志组件-业务轨迹监控-非后台批次调用
     *
     * @param SubjectID
     * @param ItemID
     */
    public static void logTrack(String SubjectID, String KeyNo, String LogDes) {
        if (SubjectID != null && !SubjectID.equals(""))
            LogProcessor.log("02", SubjectID, "", KeyNo, LogDes, "null");
    }

    /**
     * 日志组件-业务轨迹监控-后台批次调用接口 LogID[0]为SubjectID="TASK"+LDTASK.TASKCODE
     * LogID[1]为LDTASKRUNLOG.SERIALNO
     *
     */
    public static void logTrack(GlobalInput o, String KeyNo, String LogDes) {
        if (o != null && o.LogID[0] != null && !o.LogID[0].equals("")
                && o.LogID[1] != null && !o.LogID[1].equals(""))
            LogProcessor.log("02", o.LogID[0], o.LogID[1], KeyNo, LogDes,
                    "null");
    }

    /**
     * 日志组件-业务结果监控-非后台批次调用
     *
     * @param SubjectID
     * @param ItemID
     */
    public static void logResult(String SubjectID, String KeyNo, String LogDes) {
        if (SubjectID != null && !SubjectID.equals(""))
            LogProcessor.log("03", SubjectID, "", KeyNo, LogDes, "null");
    }

    /**
     * 日志组件-业务结果监控-后台批次调用接口 LogID[0]为SubjectID="TASK"+LDTASK.TASKCODE
     * LogID[1]为LDTASKRUNLOG.SERIALNO
     *
     */
    public static void logResult(GlobalInput o, String KeyNo, String LogDes) {
        if (o != null && o.LogID[0] != null && !o.LogID[0].equals("")
                && o.LogID[1] != null && !o.LogID[1].equals(""))
            LogProcessor.log("03", o.LogID[0], o.LogID[1], KeyNo, LogDes,
                    "null");
    }

    /**
     * 日志组件-业务状态监控-非后台批次调用
     *
     * @param State
     * @param KeyType
     * @param KeyNo
     */

    public static void logState(String SubjectID, String KeyNo, String LogDes,
                                String State) {
        if (SubjectID != null && !SubjectID.equals(""))
            LogProcessor.log("01", SubjectID, "", KeyNo, LogDes, State);
    }

    /**
     * 日志组件-业务状态监控-后台批次调用接口 LogID[0]为SubjectID="TASK"+LDTASK.TASKCODE
     * LogID[1]为LDTASKRUNLOG.SERIALNO
     *
     */
    public static void logState(GlobalInput o, String KeyNo, String LogDes,
                                String State) {
        if (o != null && o.LogID[0] != null && !o.LogID[0].equals("")
                && o.LogID[1] != null && !o.LogID[1].equals(""))
            LogProcessor
                    .log("01", o.LogID[0], o.LogID[1], KeyNo, LogDes, State);
    }

    // capacity
    /**
     * 日志组件-业务性能监控-非后台批次调用
     *
     * @param State
     * @param KeyType
     * @param KeyNo
     */

    public static void logPerformance(String SubjectID, String KeyNo,
                                      String LogDes, String State) {
        if (SubjectID != null && !SubjectID.equals(""))
            LogProcessor.log("04", SubjectID, "", KeyNo, LogDes, State);
    }

    /**
     * 日志组件-业务性能监控-后台批次调用接口 LogID[0]为SubjectID="TASK"+LDTASK.TASKCODE
     * LogID[1]为LDTASKRUNLOG.SERIALNO
     *
     */
    public static void logPerformance(GlobalInput o, String KeyNo,
                                      String LogDes, String State) {
        if (o != null && o.LogID[0] != null && !o.LogID[0].equals("")
                && o.LogID[1] != null && !o.LogID[1].equals(""))
            LogProcessor
                    .log("04", o.LogID[0], o.LogID[1], KeyNo, LogDes, State);
    }

    /**
     * 计算日期的函数 author: HST
     * 参照日期指当按照年月进行日期的计算的时候，参考的日期，如下例，结果返回2002-03-31
     * <p><b>Example: </b><p>
     * <p>FDate tD=new FDate();<p>
     * <p>Date baseDate =new Date();<p>
     * <p>baseDate=tD.getDate("2000-02-29");<p>
     * <p>Date comDate =new Date();<p>
     * <p>comDate=tD.getDate("1999-12-31");<p>
     * <p>int inteval=1;<p>
     * <p>String tUnit="M";<p>
     * <p>Date tDate =new Date();<p>
     * <p>tDate=PubFun.calDate(baseDate,inteval,tUnit,comDate);<p>
     * <p>System.out.println(tDate.toString());<p>
     * @param baseDate 起始日期
     * @param interval 时间间隔
     * @param unit 时间间隔单位
     * @param compareDate 参照日期
     * @return Date类型变量
     */
    public static Date calDate(Date baseDate, int interval, String unit,
                               Date compareDate) {
        Date returnDate = null;

        GregorianCalendar mCalendar = new GregorianCalendar();
        mCalendar.setTime(baseDate);
        if (unit.equals("Y")) {
            mCalendar.add(Calendar.YEAR, interval);
        }
        if (unit.equals("M")) {
            mCalendar.add(Calendar.MONTH, interval);
        }
        if (unit.equals("D")) {
            mCalendar.add(Calendar.DATE, interval);
        }

        if (compareDate != null) {
            GregorianCalendar cCalendar = new GregorianCalendar();
            cCalendar.setTime(compareDate);

            int mYears = mCalendar.get(Calendar.YEAR);
            int mMonths = mCalendar.get(Calendar.MONTH);
            int cMonths = cCalendar.get(Calendar.MONTH);
            int cDays = cCalendar.get(Calendar.DATE);

            if (unit.equals("Y")) {
                cCalendar.set(mYears, cMonths, cDays);
                if (cCalendar.before(mCalendar)) {
                    mCalendar.set(mYears + 1, cMonths, cDays);
                    returnDate = mCalendar.getTime();
                } else {
                    returnDate = cCalendar.getTime();
                }
            }
            if (unit.equals("M")) {
                cCalendar.set(mYears, mMonths, cDays);
                if (cCalendar.before(mCalendar)) {
                    mCalendar.set(mYears, mMonths + 1, cDays);
                    returnDate = mCalendar.getTime();
                } else {
                    returnDate = cCalendar.getTime();
                }
            }
            if (unit.equals("D")) {
                returnDate = mCalendar.getTime();
            }
        } else {
            returnDate = mCalendar.getTime();
        }

        return returnDate;
    }

    /**
     * 重载计算日期，参数见楼上，add by Minim
     * @param baseDate String
     * @param interval int
     * @param unit String
     * @param compareDate String
     * @return String
     */
    public static String calDate(String baseDate, int interval, String unit,
                                 String compareDate) {
        try {
            FDate tFDate = new FDate();
            Date bDate = tFDate.getDate(baseDate);
            Date cDate = tFDate.getDate(compareDate);
            return tFDate.getString(calDate(bDate, interval, unit, cDate));
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    /**
     * 通过起始日期和终止日期计算以时间间隔单位为计量标准的时间间隔 author: HST
     * <p><b>Example: </b><p>
     * <p>参照calInterval(String  cstartDate, String  cendDate, String unit)，前两个变量改为日期型即可<p>
     * @param startDate 起始日期，Date变量
     * @param endDate 终止日期，Date变量
     * @param unit 时间间隔单位，可用值("Y"--年 "M"--月 "D"--日)
     * @return 时间间隔,整形变量int
     */
    public static int calInterval(Date startDate, Date endDate, String unit) {
        int interval = 0;

        GregorianCalendar sCalendar = new GregorianCalendar();
        sCalendar.setTime(startDate);
        int sYears = sCalendar.get(Calendar.YEAR);
        int sMonths = sCalendar.get(Calendar.MONTH);
        int sDays = sCalendar.get(Calendar.DAY_OF_MONTH);
        int sDaysOfYear = sCalendar.get(Calendar.DAY_OF_YEAR);

        GregorianCalendar eCalendar = new GregorianCalendar();
        eCalendar.setTime(endDate);
        int eYears = eCalendar.get(Calendar.YEAR);
        int eMonths = eCalendar.get(Calendar.MONTH);
        int eDays = eCalendar.get(Calendar.DAY_OF_MONTH);
        int eDaysOfYear = eCalendar.get(Calendar.DAY_OF_YEAR);

        if (unit.equals("Y")) {
            interval = eYears - sYears;
            if (eMonths < sMonths) {
                interval--;
            } else {
                if (eMonths == sMonths && eDays < sDays) {
                    interval--;
                    if (eMonths == 1) { //如果同是2月，校验润年问题
                        if ((sYears % 4) == 0 && (eYears % 4) != 0) { //如果起始年是润年，终止年不是润年
                            if (eDays == 28) { //如果终止年不是润年，且2月的最后一天28日，那么补一
                                interval++;
                            }
                        }
                    }
                }
            }
        }
        if (unit.equals("M")) {
            interval = eYears - sYears;
            interval = interval * 12;

            interval = eMonths - sMonths + interval;
            if (eDays < sDays) {
                interval--;
                //eDays如果是月末，则认为是满一个月
                int maxDate = eCalendar.getActualMaximum(Calendar.DATE);
                if (eDays == maxDate) {
                    interval++;
                }
            }
        }
        if (unit.equals("D")) {
            interval = eYears - sYears;
            interval = interval * 365;
            interval = eDaysOfYear - sDaysOfYear + interval;

            // 处理润年
            int n = 0;
            eYears--;
            if (eYears > sYears) {
                int i = sYears % 4;
                if (i == 0) {
                    sYears++;
                    n++;
                }
                int j = (eYears) % 4;
                if (j == 0) {
                    eYears--;
                    n++;
                }
                n += (eYears - sYears) / 4;
            }
            if (eYears == sYears) {
                int i = sYears % 4;
                if (i == 0) {
                    n++;
                }
            }
            interval += n;
        }
        return interval;
    }

    /**
     * 通过起始日期和终止日期计算以时间间隔单位为计量标准的时间间隔，舍弃法 author: HST
     * 起始日期，(String,格式："YYYY-MM-DD")
     * @param cstartDate String
     * 终止日期，(String,格式："YYYY-MM-DD")
     * @param cendDate String
     * 时间间隔单位，可用值("Y"--年 "M"--月 "D"--日)
     * @param unit String
     * 时间间隔,整形变量int
     * @return int
     */
    public static int calInterval(String cstartDate, String cendDate,
                                  String unit) {
        FDate fDate = new FDate();
        Date startDate = fDate.getDate(cstartDate);
        Date endDate = fDate.getDate(cendDate);
        if (fDate.mErrors.needDealError()) {
            return 0;
        }

        int interval = 0;

        GregorianCalendar sCalendar = new GregorianCalendar();
        sCalendar.setTime(startDate);
        int sYears = sCalendar.get(Calendar.YEAR);
        int sMonths = sCalendar.get(Calendar.MONTH);
        int sDays = sCalendar.get(Calendar.DAY_OF_MONTH);
        int sDaysOfYear = sCalendar.get(Calendar.DAY_OF_YEAR);

        GregorianCalendar eCalendar = new GregorianCalendar();
        eCalendar.setTime(endDate);
        int eYears = eCalendar.get(Calendar.YEAR);
        int eMonths = eCalendar.get(Calendar.MONTH);
        int eDays = eCalendar.get(Calendar.DAY_OF_MONTH);
        int eDaysOfYear = eCalendar.get(Calendar.DAY_OF_YEAR);

        if (StrTool.cTrim(unit).equals("Y")) {
            interval = eYears - sYears;

            if (eMonths < sMonths) {
                interval--;
            } else {
                if (eMonths == sMonths && eDays < sDays) {
                    interval--;
                    if (eMonths == 1) { //如果同是2月，校验润年问题
                        if ((sYears % 4) == 0 && (eYears % 4) != 0) { //如果起始年是润年，终止年不是润年
                            if (eDays == 28) { //如果终止年不是润年，且2月的最后一天28日，那么补一
                                interval++;
                            }
                        }
                    }
                }
            }
        }
        if (StrTool.cTrim(unit).equals("M")) {
            interval = eYears - sYears;
            interval = interval * 12;
            interval = eMonths - sMonths + interval;

            if (eDays < sDays) {
                interval--;
                //eDays如果是月末，则认为是满一个月
                int maxDate = eCalendar.getActualMaximum(Calendar.DATE);
                if (eDays == maxDate) {
                    interval++;
                    if (sDays == 1) {
                        interval++;
                    }

                }
            }
        }
        if (StrTool.cTrim(unit).equals("D")) {
            interval = eYears - sYears;
            interval = interval * 365;

            interval = eDaysOfYear - sDaysOfYear + interval;

            // 处理润年
            int n = 0;
            eYears--;
            if (eYears > sYears) {
                int i = sYears % 4;
                if (i == 0) {
                    sYears++;
                    n++;
                }
                int j = (eYears) % 4;
                if (j == 0) {
                    eYears--;
                    n++;
                }
                n += (eYears - sYears) / 4;
            }
            if (eYears == sYears) {
                int i = sYears % 4;
                if (i == 0) {
                    n++;
                }
            }
            interval += n;
        }
        return interval;
    }

    /**
     * 通过起始日期和终止日期计算以时间间隔单位为计量标准的时间间隔，约进法 author: YangZhao，Minim
     * 起始日期，(String,格式："YYYY-MM-DD")
     * @param cstartDate String
     * 终止日期，(String,格式："YYYY-MM-DD")
     * @param cendDate String
     * 时间间隔单位，可用值("Y"--年 "M"--月 "D"--日)
     * @param unit String
     * 时间间隔,整形变量int
     * @return int
     */
    public static int calInterval2(String cstartDate, String cendDate,
                                   String unit) {
        FDate fDate = new FDate();
        Date startDate = fDate.getDate(cstartDate);
        Date endDate = fDate.getDate(cendDate);
        if (fDate.mErrors.needDealError()) {
            return 0;
        }

        int interval = 0;

        GregorianCalendar sCalendar = new GregorianCalendar();
        sCalendar.setTime(startDate);
        int sYears = sCalendar.get(Calendar.YEAR);
        int sMonths = sCalendar.get(Calendar.MONTH);
        int sDays = sCalendar.get(Calendar.DAY_OF_MONTH);
        int sDaysOfYear = sCalendar.get(Calendar.DAY_OF_YEAR);

        GregorianCalendar eCalendar = new GregorianCalendar();
        eCalendar.setTime(endDate);
        int eYears = eCalendar.get(Calendar.YEAR);
        int eMonths = eCalendar.get(Calendar.MONTH);
        int eDays = eCalendar.get(Calendar.DAY_OF_MONTH);
        int eDaysOfYear = eCalendar.get(Calendar.DAY_OF_YEAR);

        if (StrTool.cTrim(unit).equals("Y")) {
            interval = eYears - sYears;

            if (eMonths > sMonths) {
                interval++;
            } else {
                if (eMonths == sMonths && eDays > sDays) {
                    interval++;
                    if (eMonths == 1) { //如果同是2月，校验润年问题
                        if ((sYears % 4) == 0 && (eYears % 4) != 0) { //如果起始年是润年，终止年不是润年
                            if (eDays == 28) { //如果终止年不是润年，且2月的最后一天28日，那么减一
                                interval--;
                            }
                        }
                    }
                }
            }
        }
        if (StrTool.cTrim(unit).equals("M")) {
            interval = eYears - sYears;
            interval = interval * 12;
            interval = eMonths - sMonths + interval;

            if (eDays > sDays) {
                interval++;
                //eDays如果是月末，则认为是满一个月
                int maxDate = eCalendar.getActualMaximum(Calendar.DATE);
                if (eDays == maxDate) {
                    interval--;
                    if (sDays == 1) {
                        interval++;
                    }
                }
            }
        }
        if (StrTool.cTrim(unit).equals("D")) {
            interval = eYears - sYears;
            interval = interval * 365;

            interval = eDaysOfYear - sDaysOfYear + interval;

            // 处理润年
            int n = 0;
            eYears--;
            if (eYears > sYears) {
                int i = sYears % 4;
                if (i == 0) {
                    sYears++;
                    n++;
                }
                int j = (eYears) % 4;
                if (j == 0) {
                    eYears--;
                    n++;
                }
                n += (eYears - sYears) / 4;
            }
            if (eYears == sYears) {
                int i = sYears % 4;
                if (i == 0) {
                    n++;
                }
            }
            interval += n;
        }
        return interval;
    }

    /**
     * 通过起始日期和终止日期计算以时间间隔单位为计量标准的时间间隔，约进法 author: YangZhao，Minim
     * 起始日期，(String,格式："YYYY-MM-DD")
     * @param cstartDate String
     * 终止日期，(String,格式："YYYY-MM-DD")
     * @param cendDate String
     * 时间间隔单位，可用值("Y"--年 "M"--月 "D"--日)
     * @param unit String
     * 时间间隔,整形变量int
     * @return int
     */
    public static int calInterval3(String cstartDate, String cendDate,
                                   String unit) {
        FDate fDate = new FDate();
        Date startDate = fDate.getDate(cstartDate);
        Date endDate = fDate.getDate(cendDate);
        if (fDate.mErrors.needDealError()) {
            return 0;
        }

        int interval = 0;

        GregorianCalendar sCalendar = new GregorianCalendar();
        sCalendar.setTime(startDate);
        int sYears = sCalendar.get(Calendar.YEAR);
        int sMonths = sCalendar.get(Calendar.MONTH);
        int sDays = sCalendar.get(Calendar.DAY_OF_MONTH);
        int sDaysOfYear = sCalendar.get(Calendar.DAY_OF_YEAR);

        GregorianCalendar eCalendar = new GregorianCalendar();
        eCalendar.setTime(endDate);
        int eYears = eCalendar.get(Calendar.YEAR);
        int eMonths = eCalendar.get(Calendar.MONTH);
        int eDays = eCalendar.get(Calendar.DAY_OF_MONTH);
        int eDaysOfYear = eCalendar.get(Calendar.DAY_OF_YEAR);

        if (StrTool.cTrim(unit).equals("Y")) {
            interval = eYears - sYears;

            if (eMonths > sMonths) {
                interval++;
            } else {
                if (eMonths == sMonths && eDays > sDays) {
                    interval++;
                    if (eMonths == 1) { //如果同是2月，校验润年问题
                        if ((sYears % 4) == 0 && (eYears % 4) != 0) { //如果起始年是润年，终止年不是润年
                            if (eDays == 28) { //如果终止年不是润年，且2月的最后一天28日，那么减一
                                interval--;
                            }
                        }
                    }
                }
            }
        }
        if (StrTool.cTrim(unit).equals("M")) {
            interval = eYears - sYears;
            interval = interval * 12;
            interval = eMonths - sMonths + interval;

            if (eDays > sDays) {
                interval++;
                //eDays如果是月末，则认为是满一个月
                int maxDate = eCalendar.getActualMaximum(Calendar.DATE);
                if (eDays == maxDate) {
                    interval--;
                    if (sDays == 1) {
                        interval++;
                    }
                }
            }
        }
        if (StrTool.cTrim(unit).equals("D")) {
            interval = eYears - sYears;
            interval = interval * 365;

            interval = eDaysOfYear - sDaysOfYear + interval + 1;

            // 处理润年
            int n = 0;
            eYears--;
            if (eYears > sYears) {
                int i = sYears % 4;
                if (i == 0) {
                    sYears++;
                    n++;
                }
                int j = (eYears) % 4;
                if (j == 0) {
                    eYears--;
                    n++;
                }
                n += (eYears - sYears) / 4;
            }
            if (eYears == sYears) {
                int i = sYears % 4;
                if (i == 0) {
                    n++;
                }
            }
            interval += n;
        }
        return interval;
    }


    /**
     * 通过传入的日期可以得到所在月的第一天和最后一天的日期 author: LH
     * 日期，(String,格式："YYYY-MM-DD")
     * @param tDate String
     * 本月开始和结束日期，返回String[2]
     * @return String[]
     */
    public static String[] calFLDate(String tDate) {
        String MonDate[] = new String[2];
        FDate fDate = new FDate();
        Date CurDate = fDate.getDate(tDate);
        GregorianCalendar mCalendar = new GregorianCalendar();
        mCalendar.setTime(CurDate);
        int Years = mCalendar.get(Calendar.YEAR);
        int Months = mCalendar.get(Calendar.MONTH);
        int FirstDay = mCalendar.getActualMinimum(Calendar.DAY_OF_MONTH);
        int LastDay = mCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        mCalendar.set(Years, Months, FirstDay);
        MonDate[0] = fDate.getString(mCalendar.getTime());
        mCalendar.set(Years, Months, LastDay);
        MonDate[1] = fDate.getString(mCalendar.getTime());
        return MonDate;
    }

    /**
     * 得到默认的JDBCUrl
     * @return JDBCUrl
     */
    public static JdbcUrl getDefaultUrl() {
        JdbcUrl tUrl = new JdbcUrl();
        return tUrl;
    }

    /**
     * 将字符串补数,将sourString的<br>后面</br>用cChar补足cLen长度的字符串,如果字符串超长，则不做处理
     * <p><b>Example: </b><p>
     * <p>RCh("Minim", "0", 10) returns "Minim00000"<p>
     * @param sourString 源字符串
     * @param cChar 补数用的字符
     * @param cLen 字符串的目标长度
     * @return 字符串
     */
    public static String RCh(String sourString, String cChar, int cLen) {
        int tLen = sourString.length();
        int i, j, iMax;
        String tReturn = "";
        if (tLen >= cLen) {
            return sourString;
        }
        iMax = cLen - tLen;
        for (i = 0; i < iMax; i++) {
            tReturn = tReturn + cChar;
        }
        tReturn = sourString.trim() + tReturn.trim();
        return tReturn;
    }

    /**
     * 将字符串补数,将sourString的<br>前面</br>用cChar补足cLen长度的字符串,如果字符串超长，则不做处理
     * <p><b>Example: </b><p>
     * <p>LCh("Minim", "0", 10) returns "00000Minim"<p>
     * @param sourString 源字符串
     * @param cChar 补数用的字符
     * @param cLen 字符串的目标长度
     * @return 字符串
     */
    public static String LCh(String sourString, String cChar, int cLen) {
        int tLen = sourString.length();
        int i, j, iMax;
        String tReturn = "";
        if (tLen >= cLen) {
            return sourString;
        }
        iMax = cLen - tLen;
        for (i = 0; i < iMax; i++) {
            tReturn = cChar + tReturn;
        }
        tReturn = tReturn.trim() + sourString.trim();
        return tReturn;
    }

    /**
     * 比较获取两天中较后的一天
     * @param date1 String
     * @param date2 String
     * @return String
     */
    public static String getLaterDate(String date1, String date2) {
        try {
            date1 = StrTool.cTrim(date1);
            date2 = StrTool.cTrim(date2);
            if (date1.equals("")) {
                return date2;
            }
            if (date2.equals("")) {
                return date1;
            }
            FDate fd = new FDate();
            Date d1 = fd.getDate(date1);
            Date d2 = fd.getDate(date2);
            if (d1.after(d2)) {
                return date1;
            }
            return date2;
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }

    }

    /**
     * 比较获取两天中较早的一天
     * @param date1 String
     * @param date2 String
     * @return String
     */
    public static String getBeforeDate(String date1, String date2) {
        try {
            date1 = StrTool.cTrim(date1);
            date2 = StrTool.cTrim(date2);
            if (date1.equals("")) {
                return date2;
            }
            if (date2.equals("")) {
                return date1;
            }
            FDate fd = new FDate();
            Date d1 = fd.getDate(date1);
            Date d2 = fd.getDate(date2);
            if (d1.before(d2)) {
                return date1;
            }
            return date2;
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }

    }

    /**
     * 得到当前系统日期 author: YT
     * @return 当前日期的格式字符串,日期格式为"yyyy-MM-dd"
     */
    public static String getCurrentDate() {

        GregorianCalendar tGCalendar = new GregorianCalendar();
        StringBuffer tStringBuffer = new StringBuffer(10);
        int sYears = tGCalendar.get(Calendar.YEAR);
        tStringBuffer.append(sYears);
        tStringBuffer.append('-');
        int sMonths = tGCalendar.get(Calendar.MONTH)+1;
        if(sMonths < 10){
            tStringBuffer.append('0');
        }
        tStringBuffer.append(sMonths);
        tStringBuffer.append('-');
        int sDays = tGCalendar.get(Calendar.DAY_OF_MONTH);
        if(sDays < 10){
            tStringBuffer.append('0');
        }
        tStringBuffer.append(sDays);
        String tString = tStringBuffer.toString();
        return tString;

    }

    public static String getCurrentDate2() {
        String pattern = "yyyyMMdd";
        SimpleDateFormat df = new SimpleDateFormat(pattern);
        Date today = new Date();
        String tString = df.format(today);
        return tString;
    }


    /**
     * 得到当前系统时间 author: YT
     * @return 当前时间的格式字符串，时间格式为"HH:mm:ss"
     */
    public static String getCurrentTime() {

        GregorianCalendar tGCalendar = new GregorianCalendar();
        StringBuffer tStringBuffer = new StringBuffer(8);
        int sHOUR = tGCalendar.get(Calendar.HOUR_OF_DAY);
        if(sHOUR < 10){
            tStringBuffer.append('0');
        }
        tStringBuffer.append(sHOUR);
        tStringBuffer.append(':');
        int sMINUTE = tGCalendar.get(Calendar.MINUTE);
        if(sMINUTE < 10){
            tStringBuffer.append('0');
        }
        tStringBuffer.append(sMINUTE);
        tStringBuffer.append(':');
        int sSECOND = tGCalendar.get(Calendar.SECOND);
        if(sSECOND < 10){
            tStringBuffer.append('0');
        }
        tStringBuffer.append(sSECOND);
        String tString = tStringBuffer.toString();
        return tString;

    }

    /**
     * 得到当前系统时间
     * @return 当前时间的格式字符串，时间格式为"HHmmss"
     */
    public static String getCurrentTime2() {
        String pattern = "HHmmss";
        SimpleDateFormat df = new SimpleDateFormat(pattern);
        Date today = new Date();
        String tString = df.format(today);
        return tString;
    }


    /**
     * 得到流水号前导 author: YT
     * @param comCode 机构代码
     * @return 流水号的前导字符串
     */
    public static String getNoLimit(String comCode) {
        comCode = comCode.trim();
        int tLen = comCode.length();
        if (tLen > 6) {
            comCode = comCode.substring(0, 6);
        }
        if (tLen < 6) {
            comCode = RCh(comCode, "0", 6);
        }
        String tString = "";
        tString = comCode + getCurrentDate().substring(0, 4);
        return tString;
    }

    /**
     * picc获取管理机构，截取管理代码的第3-6位（二级机构+三级机构）
     * 再加上日期编码的两位年两位月日日 052203
     * @param comCode String
     * @return String
     */
    public static String getPiccNoLimit(String comCode) {
        comCode = comCode.trim();
        System.out.println("comCode :" + comCode);
        int tLen = comCode.length();
        if (tLen == 8) {
            comCode = comCode.substring(2, 6);
        }
        if (tLen == 4) {
            comCode = comCode.substring(2, 4) + "00";
        }
        System.out.println("SubComCode :" + comCode);
        String tString = "";
        tString = comCode + getCurrentDate().substring(2, 4)
                + getCurrentDate().substring(5, 7)
                + getCurrentDate().substring(8, 10);
        System.out.println("PubFun getPiccNoLimit : " + tString);
        return tString;
    }

    /**
     * 该函数得到c_Str中的第c_i个以c_Split分割的字符串
     * @param c_Str 目标字符串
     * @param c_i 位置
     * @param c_Split   分割符
     * @return 如果发生异常，则返回空
     */
    public static String getStr(String c_Str, int c_i, String c_Split) {
        String t_Str1 = "", t_Str2 = "", t_strOld = "";
        int i = 0, i_Start = 0;
//        int j_End = 0;
        t_Str1 = c_Str;
        t_Str2 = c_Split;
        i = 0;
        try {
            while (i < c_i) {
                i_Start = t_Str1.indexOf(t_Str2, 0);
                if (i_Start >= 0) {
                    i = i + 1;
                    t_strOld = t_Str1;
                    t_Str1 = t_Str1.substring(i_Start + t_Str2.length(),
                            t_Str1.length());
                } else {
                    if (i != c_i - 1) {
                        t_Str1 = "";
                    }
                    break;
                }
            }

            if (i_Start >= 0) {
                t_Str1 = t_strOld.substring(0, i_Start);
            }
        } catch (Exception ex) {
            t_Str1 = "";
        }
        return t_Str1;
    }

    /**
     * 把数字金额转换为中文大写金额 author: HST
     * @param money 数字金额(double)
     * @return 中文大写金额(String)
     */
    public static String getChnMoney(double money) {
        String ChnMoney = "";
        String s0 = "";

        // 在原来版本的程序中，getChnMoney(585.30)得到的数据是585.29。

        if (money == 0.0) {
            ChnMoney = "零元整";
            return ChnMoney;
        }

        if (money < 0) {
            s0 = "负";
            money = money * ( -1);
        }

        String sMoney = new DecimalFormat("0").format(money * 100);

        int nLen = sMoney.length();
        String sInteger;
        String sDot;
        if (nLen < 2) {
            //add by JL at 2004-9-14
            sInteger = "";
            if (nLen == 1) {
                sDot = "0" + sMoney.substring(nLen - 1, nLen);
            } else {
                sDot = "0";
            }
        } else {
            sInteger = sMoney.substring(0, nLen - 2);
            sDot = sMoney.substring(nLen - 2, nLen);
        }

        String sFormatStr = PubFun.formatStr(sInteger);

        String s1 = PubFun.getChnM(sFormatStr.substring(0, 4), "亿");

        String s2 = PubFun.getChnM(sFormatStr.substring(4, 8), "万");

        String s3 = PubFun.getChnM(sFormatStr.substring(8, 12), "");

        String s4 = PubFun.getDotM(sDot);

        if (s1.length() > 0 && s1.substring(0, 1).equals("0")) {
            s1 = s1.substring(1,
                    s1.length());
        }
        if (s1.length() > 0 &&
                s1.substring(s1.length() - 1, s1.length()).equals("0")
                && s2.length() > 0 && s2.substring(0, 1).equals("0")) {
            s1 = s1.substring(0, s1.length() - 1);
        }
        if (s2.length() > 0 &&
                s2.substring(s2.length() - 1, s2.length()).equals("0")
                && s3.length() > 0 && s3.substring(0, 1).equals("0")) {
            s2 = s2.substring(0, s2.length() - 1);
        }
        if (s4.equals("00")) {
            s4 = "";
            if (s3.length() > 0 &&
                    s3.substring(s3.length() - 1, s3.length()).equals("0")) {
                s3 = s3.substring(0, s3.length() - 1);
            }
        }
        if (s3.length() > 0 &&
                s3.substring(s3.length() - 1, s3.length()).equals("0")
                && s4.length() > 0 && s4.substring(0, 1).equals("0")) {
            s3 = s3.substring(0, s3.length() - 1);
        }
        if (s4.length() > 0 &&
                s4.substring(s4.length() - 1, s4.length()).equals("0")) {
            s4 = s4.substring(0, s4.length() - 1);
        }
        if (s3.equals("0")) {
            s3 = "";
            s4 = "0" + s4;
        }

        ChnMoney = s0 + s1 + s2 + s3 + "元" + s4;
        if (ChnMoney.substring(0, 1).equals("0")) {
            ChnMoney = ChnMoney.substring(1,
                    ChnMoney.length());
        }
        for (int i = 0; i < ChnMoney.length(); i++) {
            if (ChnMoney.substring(i, i + 1).equals("0")) {
                ChnMoney = ChnMoney.substring(0, i) + "零" +
                        ChnMoney.substring(i + 1, ChnMoney.length());
            }
        }

        if (sDot.substring(1, 2).equals("0")) {
            ChnMoney += "整";
        }

        return ChnMoney;
    }

    /**
     * 得到money的角分信息
     * @param sIn String
     * @return String
     */
    private static String getDotM(String sIn) {
        String sMoney = "";
        if (!sIn.substring(0, 1).equals("0")) {
            sMoney += getNum(sIn.substring(0, 1)) + "角";
        } else {
            sMoney += "0";
        }
        if (!sIn.substring(1, 2).equals("0")) {
            sMoney += getNum(sIn.substring(1, 2)) + "分";
        } else {
            sMoney += "0";
        }

        return sMoney;
    }

    /**
     * 添加仟、佰、拾等单位信息
     * @param strUnit String
     * @param digit String
     * @return String
     */
    private static String getChnM(String strUnit, String digit) {
        String sMoney = "";
        boolean flag = false;

        if (strUnit.equals("0000")) {
            sMoney += "0";
            return sMoney;
        }
        if (!strUnit.substring(0, 1).equals("0")) {
            sMoney += getNum(strUnit.substring(0, 1)) + "仟";
        } else {
            sMoney += "0";
            flag = true;
        }
        if (!strUnit.substring(1, 2).equals("0")) {
            sMoney += getNum(strUnit.substring(1, 2)) + "佰";
            flag = false;
        } else {
            if (flag == false) {
                sMoney += "0";
                flag = true;
            }
        }
        if (!strUnit.substring(2, 3).equals("0")) {
            sMoney += getNum(strUnit.substring(2, 3)) + "拾";
            flag = false;
        } else {
            if (flag == false) {
                sMoney += "0";
                flag = true;
            }
        }
        if (!strUnit.substring(3, 4).equals("0")) {
            sMoney += getNum(strUnit.substring(3, 4));
        } else {
            if (flag == false) {
                sMoney += "0";
                flag = true;
            }
        }

        if (sMoney.substring(sMoney.length() - 1, sMoney.length()).equals("0")) {
            sMoney = sMoney.substring(0, sMoney.length() - 1) + digit.trim() +
                    "0";
        } else {
            sMoney += digit.trim();
        }
        return sMoney;
    }

    /**
     * 格式化字符
     * @param sIn String
     * @return String
     */
    private static String formatStr(String sIn) {
        int n = sIn.length();
        String sOut = sIn;
//        int i = n % 4;

        for (int k = 1; k <= 12 - n; k++) {
            sOut = "0" + sOut;
        }
        return sOut;
    }

    /**
     * 获取阿拉伯数字和中文数字的对应关系
     * @param value String
     * @return String
     */
    private static String getNum(String value) {
        String sNum = "";
        Integer I = new Integer(value);
        int iValue = I.intValue();
        switch (iValue) {
            case 0:
                sNum = "零";
                break;
            case 1:
                sNum = "壹";
                break;
            case 2:
                sNum = "贰";
                break;
            case 3:
                sNum = "叁";
                break;
            case 4:
                sNum = "肆";
                break;
            case 5:
                sNum = "伍";
                break;
            case 6:
                sNum = "陆";
                break;
            case 7:
                sNum = "柒";
                break;
            case 8:
                sNum = "捌";
                break;
            case 9:
                sNum = "玖";
                break;
        }
        return sNum;
    }

    /**
     * 如果一个字符串数字中小数点后全为零，则去掉小数点及零
     * @param Value String
     * @return String
     */
    public static String getInt(String Value) {
        if (Value == null) {
            return null;
        }
        String result = "";
        boolean mflag = true;
        int m = 0;
        m = Value.lastIndexOf(".");
        if (m == -1) {
            result = Value;
        } else {
            for (int i = m + 1; i <= Value.length() - 1; i++) {
                if (Value.charAt(i) != '0') {
                    result = Value;
                    mflag = false;
                    break;
                }
            }
            if (mflag == true) {
                result = Value.substring(0, m);
            }
        }
        return result;
    }

    /**
     * 得到近似值
     * @param aValue double
     * @return double
     */
    public static double getApproximation(double aValue) {
        if (Math.abs(aValue) <= 0.01) {
            aValue = 0;
        }
        return aValue;
    }

    /**
     * 根据输入标记为间隔符号，拆分字符串
     * @param strMain String
     * @param strDelimiters String
     * 失败返回NULL
     * @return String[]
     */
    public static String[] split(String strMain, String strDelimiters) {
        int i;
        int intIndex = 0; //记录分隔符位置，以取出子串
        Vector vResult = new Vector(); //存储子串的数组
        String strSub = ""; //存放子串的中间变量

        strMain = strMain.trim();

        //若主字符串比分隔符串还要短的话,则返回空字符串
        if (strMain.length() <= strDelimiters.length()) {
            System.out.println("分隔符串长度大于等于主字符串长度，不能进行拆分！");
            return null;
        }

        //取出第一个分隔符在主串中的位置
        intIndex = strMain.indexOf(strDelimiters);

        //在主串中找不到分隔符
        if (intIndex == -1) {
            String[] arrResult = {
                    strMain};
            return arrResult;
        }

        //分割主串到数组中
        while (intIndex != -1) {
            strSub = strMain.substring(0, intIndex);
            if (intIndex != 0) {
                vResult.add(strSub);
            } else {
                //break;
                vResult.add("");
            }

            strMain = strMain.substring(intIndex + strDelimiters.length()).trim();
            intIndex = strMain.indexOf(strDelimiters);
        }

        //如果最末不是分隔符，取最后的字符串
        if (!strMain.equals("") && strMain != null) {
            vResult.add(strMain);
        }

        String[] arrResult = new String[vResult.size()];
        for (i = 0; i < vResult.size(); i++) {
            arrResult[i] = (String) vResult.get(i);
        }

        return arrResult;
    }

    /**
     * 设置数字精度
     * 需要格式化的数据
     * @param value float
     * 精度描述（0.00表示精确到小数点后两位）
     * @param precision String
     * @return double
     */
    public static double setPrecision(float value, String precision) {
        return Float.parseFloat(new DecimalFormat(precision).format(value));
    }

    /**
     * 设置数字精度
     * 需要格式化的数据
     * @param value double
     * 精度描述（0.00表示精确到小数点后两位）
     * @param precision String
     * @return double
     */
    public static double setPrecision(double value, String precision) {
        int idx = precision.indexOf(".");
//        if (idx) {
//
//        }
        return Double.parseDouble(new DecimalFormat(precision).format(value));
    }

    /**
     * 把schemaset对象拷贝一份返回
     * @param srcSet SchemaSet
     * @return SchemaSet
     */
    public static SchemaSet copySchemaSet(SchemaSet srcSet) {
        Reflections reflect = new Reflections();
        try {
            if (srcSet != null && srcSet.size() > 0) {
                if (srcSet.getObj(1) == null) {
                    return null;
                }
                Class cls = srcSet.getClass();
                Schema schema = (Schema) srcSet.getObj(1).getClass().
                        newInstance();
                SchemaSet obj = (SchemaSet) cls.newInstance();
                obj.add(schema);
                reflect.transFields(obj, srcSet);
                return (SchemaSet) obj;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    /**
     * 互换LP和LC表数据
     * @param source Schema
     * @param object Schema
     * @return boolean
     */
    public static boolean exchangeSchema(Schema source, Schema object) {
        try {
            //把LP表的数据传递到LC表
            Reflections tReflections = new Reflections();
            tReflections.transFields(object, source);

            //获取一个数据库连接DB
            Method m = object.getClass().getMethod("getDB", null);
            Schema schemaDB = (Schema) m.invoke(object, null);
            //因为LP表与LC表只有EdorNo和EdorType两个关键字的差别，所以可以唯一获取LC表对应记录
            m = schemaDB.getClass().getMethod("getInfo", null);
            m.invoke(schemaDB, null);
            m = schemaDB.getClass().getMethod("getSchema", null);
            object = (Schema) m.invoke(schemaDB, null);

            //把LC表数据备份到临时表
            m = object.getClass().getMethod("getSchema", null);
            Schema tSchema = (Schema) m.invoke(object, null);

            //互换LP和LC表数据
            tReflections.transFields(object, source);
            tReflections.transFields(source, tSchema);

            return true;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }

    /**
     * 生成更新的sql列表
     * @param tables String[]
     * @param condition String
     * @param wherepart String
     * @return Vector
     */
    public static Vector formUpdateSql(String[] tables, String condition,
                                       String wherepart) {
        Vector sqlVec = new Vector();
        for (int i = 0; i < tables.length; i++) {
            sqlVec.add("update " + tables[i] + " set " + condition + " where " +
                    wherepart);
        }
        return sqlVec;
    }

    /**
     * 将账号前的0去掉
     * @param sIn String
     * @return String
     */
    public static String DeleteZero(String sIn) {
        int n = sIn.length();
        String sOut = sIn;
        int k = 0;

        while (sOut.substring(0, 1).equals("0") && n > 1) {
            sOut = sOut.substring(1, n);
            n = sOut.length();
            System.out.println(sOut);
        }

        if (sOut.equals("0")) {
            return "";
        } else {
            return sOut;
        }
    }

    /**
     * 转换JavaScript解析不了的特殊字符
     * @param s String
     * @return String
     */
    public static String changForJavaScript(String s) {
        char[] arr = s.toCharArray();
        s = "";
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == '"' || arr[i] == '\'' || arr[i] == '\n') {
                s = s + "\\";
            }

            s = s + arr[i];
        }

        return s;
    }

    /**
     * 转换JavaScript解析不了的特殊字符
     * @param s String
     * @return String
     */
    public static String changForHTML(String s) {
        char[] arr = s.toCharArray();
        s = "";

        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == '"' || arr[i] == '\'') {
                s = s + "\\";
            }

            if (arr[i] == '\n') {
                s = s + "<br>";
                continue;
            }

            s = s + arr[i];
        }

        return s;
    }

    public static String getClassFileName(Object o) {
        String fileName = o.getClass().getName();
        fileName = fileName.substring(fileName.lastIndexOf(".") + 1);
        return fileName;
    }

    public static void out(Object o, String s) {
        System.out.println(PubFun.getClassFileName(o) + " : " + s);
    }

    /**
     * 主函数，测试用
     * @param args String[]
     */
//    public static void main(String[] args) {
//        try {
////            String s = "三大件福连锁店福连锁店福连锁店连锁店福连锁店福连锁店福连锁店";
////
//        	StrTool.
////            PubFun.sendMessage("13581737078", StrTool.unicodeToGBK(s));
//        	 FDate tD=new FDate();
//             Date baseDate =new Date();
//             baseDate=tD.getDate("2000-02-29");
//             Date comDate =new Date();
//             comDate=tD.getDate("1999-12-31");
//             int inteval=1;
//             String tUnit="M";
//             Date tDate =new Date();
//             tDate=PubFun.calDate(baseDate,inteval,tUnit,comDate);
//             System.out.println(tDate.toString());
//        } catch (Exception ex) {
//            ex.printStackTrace();
//        }
//    }

    /**
     * 计算保单年度
     * @param cstartDate String
     * @param cendDate String
     * @return int
     */
    public static int calPolYear(String cstartDate, String cendDate) {
        FDate fDate = new FDate();
        Date startDate = fDate.getDate(cstartDate);
        Date endDate = fDate.getDate(cendDate);
        if (fDate.mErrors.needDealError()) {
            return 0;
        }

        int interval = 0;

        GregorianCalendar sCalendar = new GregorianCalendar();
        sCalendar.setTime(startDate);
        int sYears = sCalendar.get(Calendar.YEAR);
//        int sMonths = sCalendar.get(Calendar.MONTH);
//        int sDays = sCalendar.get(Calendar.DAY_OF_MONTH);
        int sDaysOfYear = sCalendar.get(Calendar.DAY_OF_YEAR);

        GregorianCalendar eCalendar = new GregorianCalendar();
        eCalendar.setTime(endDate);
        int eYears = eCalendar.get(Calendar.YEAR);
//        int eMonths = eCalendar.get(Calendar.MONTH);
//        int eDays = eCalendar.get(Calendar.DAY_OF_MONTH);
        int eDaysOfYear = eCalendar.get(Calendar.DAY_OF_YEAR);

        interval = eYears - sYears;
        interval = interval * 365;
        interval = eDaysOfYear - sDaysOfYear + interval;

        // 处理润年
        int n = 0;
        eYears--;
        if (eYears > sYears) {
            int i = sYears % 4;
            if (i == 0) {
                sYears++;
                n++;
            }
            int j = (eYears) % 4;
            if (j == 0) {
                eYears--;
                n++;
            }
            n += (eYears - sYears) / 4;
        }
        if (eYears == sYears) {
            int i = sYears % 4;
            if (i == 0) {
                n++;
            }
        }
        interval += n;

        int x = 365;
        int PolYear = 1;
        while (x < interval) {
            x = x + 365;
            PolYear = PolYear + 1;
        }

        return PolYear;
    }

    /**
     * 通过身份证号号获取生日日期
     * @param IdNo String
     * @return String
     */
    public static String getBirthdayFromId(String IdNo) {
        String tIdNo = StrTool.cTrim(IdNo);
        String birthday = "";
        if (tIdNo.length() != 15 && tIdNo.length() != 18) {
            return "";
        }
        if (tIdNo.length() == 18) {
            birthday = tIdNo.substring(6, 14);
            birthday = birthday.substring(0, 4) + "-" + birthday.substring(4, 6) +
                    "-" + birthday.substring(6);
        }
        if (tIdNo.length() == 15) {
            birthday = tIdNo.substring(6, 12);
            birthday = birthday.substring(0, 2) + "-" + birthday.substring(2, 4) +
                    "-" + birthday.substring(4);
            birthday = "19" + birthday;
        }
        return birthday;

    }

    /**
     * 通过身份证号获取性别
     * @param IdNo String
     * @return String
     */
    public static String getSexFromId(String IdNo) {
        String tIdNo = StrTool.cTrim(IdNo);
        if (tIdNo.length() != 15 && tIdNo.length() != 18) {
            return "";
        }
        String sex = "";
        if (tIdNo.length() == 15) {
            sex = tIdNo.substring(14, 15);
        } else {
            sex = tIdNo.substring(16, 17);
        }
        try {
            int iSex = Integer.parseInt(sex);
            iSex = iSex % 2;
            if (iSex == 0) {
                return "1";
            }
            if (iSex == 1) {
                return "0";
            }
        } catch (Exception ex) {
            return "";
        }
        return "";
    }

    /**
     * 将Schema中的MakeDate,MakeTime等默认信息填充
     * @param o Object
     */
    public static void fillDefaultField(Object o) {
        Class[] c = new Class[1];
        Method m = null;
        String[] date = new String[1];
        date[0] = PubFun.getCurrentDate();
        String[] time = new String[1];
        time[0] = PubFun.getCurrentTime();
        try {
            c[0] = Class.forName("java.lang.String");
        } catch (Exception ex) {
        }
        try {
            m = o.getClass().getMethod("setMakeDate", c);
        } catch (Exception ex) {
        }
        try {
            m.invoke(o, date);
        } catch (Exception ex) {
        }
        try {
            m = o.getClass().getMethod("setModifyDate", c);
        } catch (Exception ex) {
        }
        try {
            m.invoke(o, date);
        } catch (Exception ex) {
        }
        try {
            m = o.getClass().getMethod("setMakeTime", c);
        } catch (Exception ex) {
        }
        try {
            m.invoke(o, time);
        } catch (Exception ex) {
        }
        try {
            m = o.getClass().getMethod("setModifyTime", c);
        } catch (Exception ex) {
        }
        try {
            m.invoke(o, time);
        } catch (Exception ex) {
        }
    }

    /**
     * 重载,使Set也可以填充默认字段
     * @param set SchemaSet
     */
    public static void fillDefaultField(SchemaSet set) {
        for (int i = 1; i <= set.size(); i++) {
            fillDefaultField(set.getObj(i));
        }
    }

    /**
     * 生日是birthday 到date 的年龄
     * @param date String
     * @param birthday String
     * @return int
     */
    public static int getInsuredAppAge(String date, String birthday) {
        String in_year = birthday.split("-")[0];
        String in_month = birthday.split("-")[1];
        String in_day = birthday.split("-")[2];

        String year = date.split("-")[0];
        String month = date.split("-")[1];
        String day = date.split("-")[2];
        int age = 0;
        if (Integer.parseInt(year) > Integer.parseInt(in_year)) {
            age = Integer.parseInt(year) - Integer.parseInt(in_year);
        }
        if (Integer.parseInt(month) < Integer.parseInt(in_month)) {
            age--;
        }
        if (Integer.parseInt(month) == Integer.parseInt(in_month)) {
            if (Integer.parseInt(day) < Integer.parseInt(in_day)) {
                age--;
            }
        }
        return age;
    }

    /**
     * 可以执行dos命令
     *
     * @param Com String
     * @throws Exception
     */
    public static void sendMessage(String tPhone, String tMessage) throws
            Exception {
        if (tPhone == null || tPhone.equals("")) {
            throw new Exception("没有录入电话号码！");
        }
        if (tMessage == null || tMessage.equals("")) {
            throw new Exception("没有录入短信内容！");
        }
        TransferData tTransferData = new TransferData();
        tTransferData.setNameAndValue("mobile", tPhone);
        tTransferData.setNameAndValue("content", tMessage);
        GlobalInput tGlobalInput = new GlobalInput();
        tGlobalInput.Operator = "comp";
        tGlobalInput.ManageCom = "86";
        tGlobalInput.ComCode = "86";
        VData tVData = new VData();
        tVData.add(tTransferData);
        tVData.add(tGlobalInput);
        SendMsgMail msg = new SendMsgMail();
        if (!msg.submitData(tVData, "Message")) {
            throw new Exception("发送短信失败：" + msg.mErrors.getErrContent());
        }
    }
    /**
     *判断是否为续期应收，add by wanglong
     * @param pmContNo String
     * @param pmStatDate String
     * @param pmEndDate String
     * @return boolean
     */
    public static boolean isDueFee(String pmContNo, String pmStatDate,
                                   String pmEndDate) {
        try {
            ExeSQL tExeSQL = new ExeSQL();
            String count=null;
            StringBuffer tSBql = new StringBuffer(128);
            tSBql.append("SELECT COUNT(*) FROM LJSPay a WHERE a.otherNo='")
                    .append(pmContNo)
                    .append("'")
                    .append(" and (select count(PolNo) from LJSPayPerson where ")
                    .append(" LastPayToDate>='")
                    .append(pmStatDate)
                    .append("' and LastPayToDate<='")
                    .append(pmEndDate)
                    .append("' and GetNoticeNo=a.GetNoticeNo")
                    .append(" and payCount>1 )>0")
            ;
            String strSql = tSBql.toString();
            count = tExeSQL.getOneValue(strSql);
            if ((count == null) || count.equals("0")) {
                return false;
            }

        } catch (Exception ex) {
            ex.printStackTrace();

        }
        return true;
    }
    /**
     * 将字符串补数,将sourString的<br>前面</br>用cChar补足cLen长度的字符串,如果字符串超长，则不做处理,允许填充空格
     * <p><b>Example: </b><p>
     * <p>LCh("Minim", "0", 10) returns "00000Minim"<p>
     * @param sourString 源字符串
     * @param cChar 补数用的字符
     * @param cLen 字符串的目标长度
     * @return 字符串
     */
    public static String LFillCh(String sourString, String cChar, int cLen) {
        int tLen = sourString.length();
        int i, j, iMax;
        String tReturn = "";
        if (tLen >= cLen) {
            return sourString;
        }
        iMax = cLen - tLen;
        for (i = 0; i < iMax; i++) {
            tReturn = cChar + tReturn;
        }
        tReturn = tReturn + sourString.trim();
        return tReturn;
    }

    /**去掉换行符*/
    public static String replace_R_N(String str) {

        String dest = "";

        if (str!=null) {

            Pattern p = Pattern.compile("\r|\n");

            Matcher m = p.matcher(str);

            dest = m.replaceAll("");

        }

        return dest;

    }

    /**
     * 功能描述：将throwable的堆栈信息转移到字符串流中，用于输出
     * @param tThrowable throwable对象
     * @return 异常堆栈信息字符串
     */
    public static String getSimpleStackTrace(Throwable tThrowable)
    {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        try
        {
            tThrowable.printStackTrace(pw);
            String stackTrack = sw.toString();
            int index = stackTrack.indexOf("\n");
            if(index>0){
                return stackTrack.substring(0,index);
            }
            return stackTrack;
        }
        finally
        {
            pw.close();
        }
    }

//    /**
//	 * 用于将输入流备份的方法
//	 *
//	 * @param position
//	 *            备份的位置
//	 * @param inputstream
//	 *            输入流
//	 * @param fields
//	 *            用于从输入流中解析备份信息的HashMap
//	 */
//    public static void savaStream(InputStream pInputStream, String tFileType,String pfileName,GlobalInput gi) {
//
//		try {
//
//			String fileDir = PubFun.getFileDir(tFileType, pfileName,gi);
//
//			File f = new File(fileDir);
//			FileOutputStream fos = new FileOutputStream(f);
//			int length=-1;
//			byte[] b = new byte[4096];
//			while ((length=pInputStream.read(b)) != -1) {
//				fos.write(b,0,length);
//			}
//			fos.close();
//		} catch (Exception e1) {
//			// 如果发生异常,让流程继续走下去,只在日志中保存错误记录
//		 e1.printStackTrace();
//		}
//
//	}
    /**
     * 根据"报文类型的文件夹名"和"当天日期"，获取报文存放路径
     *
     * @param 需要存放的报文类型的文件夹名
     * @return String 报文存放路径
     * @throws Exception
     */
//	public static String getFileDir(String cPosition, String cMsgDir,GlobalInput gi)
//			throws Exception {
//		String tString = null;
//		String position = "";
//		// 若cPosition为0则将路径设为标准输出流存放路径
//		// 若cPosition为1则将路径设为标准输入流存放路径
////		if ("0".equals(cPosition)) {
////			position =ParamUtil.getOutStdMsgFileDir(gi.ComCode); //PrepositionConfig.getString("OutStdMsgFileDir");
////		} else if ("1".equals(cPosition)) {
////			position = ParamUtil.getInStdMsgFileDir(gi.ComCode);// PrepositionConfig.getString("InStdMsgFileDir");
////		}
////		else if ("2".equals(cPosition)) {
////			position = PrepositionConfig.getString("InNoStdMsgFileDir");
////		} else if ("3".equals(cPosition)) {
////			position = PrepositionConfig.getString("OutNoStdMsgFileDir");
////		} else if ("4".equals(cPosition)) {
////			position = PrepositionConfig.getString("SinosoftContFileDir");
////		} else if ("5".equals(cPosition)) {
////			position = PrepositionConfig.getString("MetLifeContFileDir");
////		} else if ("6".equals(cPosition)) {
////			position = PrepositionConfig.getString("OriginMsgDir");
////		}
////		else {
////			throw new Exception(
////				"在获取文件路径时传入了错误的参数cPosition， cPosition应该为"
////			+	"\"0\", \"1\", \"2\", \"3\"， \"4\"， \"5\"， \"6\"之一。");
////		}
////		String HomeDir =   ParamUtil.getHomeDir(gi.ComCode);  //PrepositionConfig.getString("HomeDir");
////		String FileContent = ParamUtil.getFileDir(gi.ComCode);//PrepositionConfig.getString("FileDir");
//		// 精确到天的日期
//		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
//		String today = simpleDateFormat.format(new Date());
//		// 精确到月的日期
//		SimpleDateFormat simpleMonthFormat = new SimpleDateFormat("yyyyMM");
//		String thisMonth = simpleMonthFormat.format(new Date());
//		// 精确到年的日期
//		SimpleDateFormat simpleYearFormat = new SimpleDateFormat("yyyy");
//		String thisYear = simpleYearFormat.format(new Date());
//
//		// 标准/非标准格式文件
//		File formatPath = new File(HomeDir + "/" + FileContent + "/" + position);
//		// 若该路径不存在则生成路径
//		if (!formatPath.exists()) {
//			formatPath.mkdirs();
//		}
//		// 这一年的路径
//		File yearPath = new File(HomeDir + "/" + FileContent + "/" + position
//				+ "/" + thisYear);
//		// 若该路径不存在则生成路径
//		if (!yearPath.exists()) {
//			yearPath.mkdir();
//		}
//		// 这个月的路径
//		File monthPath = new File(HomeDir + "/" + FileContent + "/" + position
//				+ "/" + thisYear + "/" + thisMonth);
//		// 若该路径不存在则生成路径
//		if (!monthPath.exists()) {
//			monthPath.mkdir();
//		}
//		// 这一天的路径
//		File dayPath = new File(HomeDir + "/" + FileContent + "/" + position
//				+ "/" + thisYear + "/" + thisMonth + "/" + today);
//		// 若该路径不存在则生成路径
//		if (!dayPath.exists()) {
//			dayPath.mkdir();
//		}
//		tString = dayPath.getPath() + "/" + cMsgDir;
//
//		return tString;
//	}
}
